package com.geeguo.ebuilder.operation.base.localcache.publisher;

import com.geeguo.ebuilder.core.common.utils.GsonUtils;
import com.geeguo.ebuilder.core.localcache.event.LocalCacheChangeEventMessage;
import com.geeguo.ebuilder.core.localcache.event.LocalCacheChangeEventPublisher;
import com.geeguo.ebuilder.operation.base.core.constants.MQTopicConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class LocalCacheChangeEventPublisherImpl implements LocalCacheChangeEventPublisher {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public void publish(LocalCacheChangeEventMessage message) {
        if (message == null) {
            return;
        }
        rocketMQTemplate.convertAndSend(MQTopicConstants.OPERATION_LOCAL_CACHE_CHANGE, GsonUtils.toJson(message));
    }
}